﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Imaginecup.gameState.recycling.Sprite.Behavior;
using Imaginecup.Recycling.Object;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Imaginecup.recycling.Object.Item;
using Imaginecup.recycling.Object.Entity;
using Imaginecup.Recycling.GameMan;
using Imaginecup.gameState.recycling.Sprite;
using Imaginecup.util;
using Microsoft.Xna.Framework.Input;
using Imaginecup.gameState.recycling.Entity;
using Imaginecup.gameState.recycling.Object.UI;
using Imaginecup.recycling.Object.Menu;
using Imaginecup.gameState.recycling.Sprite.Factory;
using Imaginecup.recycling.Object;
using Imaginecup.gameState.recycling.Object;
using Imaginecup.gameState.recycling.Observable;

namespace Imaginecup.recycling.GameMan
{
    public class MenuManager
    {
        private IGameObject JumpBtn;
        private IGameObject SlidingBtn;
        private IUpdate PauseBtn;
        private GroupButtons m_GroupButton;  // 옵저버
        private IMyObserver m_Pet;
        
        public GroupButtons GroupButton
        {
            get { return m_GroupButton; }
        }

        public MenuManager(IPlayer obj)
        {
            this.m_Pet = obj.GetPet();

            m_GroupButton = new GroupButtons();
            JumpBtn = ObjectFactory.GetInstance().GetObject(ObjectID.JUMPBTN);
            SlidingBtn = ObjectFactory.GetInstance().GetObject(ObjectID.SLIDINGBTN);
            PauseBtn = new PauseButton();
            Initialize();
        }

        private void Initialize()
        {
            // 센터의 테두리를 그리기 위한 정보 초기화
            {
                Texture2D texture = ResourceManager.GetInstance().GetContent("CenterBar");
                ObjectInfo spriteInfo = new ObjectInfo(new Rectangle(158, 381, texture.Width, texture.Height));
                ISprite centerSprite = (ISprite)SpriteFactory.GetInstance().GetObject(SpriteID.NORMAL_SPRITE, spriteInfo, "CenterBar");
                RenderDrawer.GetInstance().AddSprite(centerSprite);
            }
            
            // 테두리 속의 버튼을 위한 초기화
            String[] arrTextureName = new String[5] { 
                "PAPER", "GLASS", "CAN", "PLASTIC", "ETC" };
            for (int i = 0; i < arrTextureName.Length; i++)
            {
                Texture2D texture = ResourceManager.GetInstance().GetContent(arrTextureName[i]);
                ObjectInfo spriteInfo = new ObjectInfo(
                new Rectangle(186 + i * 86, 389, texture.Width / 2, texture.Height)
                );
                ItemButton btn = new ItemButton(spriteInfo, arrTextureName[i], m_GroupButton);

                m_GroupButton.AddObserver(arrTextureName[i], btn);
            }
            m_GroupButton.AddObserver("PET", m_Pet);
        }
    }
}
